package com.freemalll.merchant.utils;

import java.util.Objects;

/**
 * @Description:
 * @Author changqi
 * @Date 2022/11/2
 **/
public class Result {

    private static final Integer SUCCESS = 200;
    private static final Integer ERROR = 500;

    /**
     * 编码 成功: 200 失败: 其他
     */
    private Integer code;

    /**
     * 提示信息
     */
    private String msg;

    /**
     * 返回结果
     */
    private Object data;

    public static Result success(String msg){
        Result result = new Result();
        result.setCode(SUCCESS);
        result.setMsg(msg);
        return result;
    }

    public static Result success(String msg, Object data){
        Result result = new Result();
        result.setCode(SUCCESS);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static Result error(String msg){
        Result result = new Result();
        result.setCode(ERROR);
        result.setMsg(msg);
        return result;
    }

    public static Result error(String msg, Object data){
        Result result = new Result();
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public Boolean isSuccess(){
        return Objects.equals(this.code, SUCCESS);
    }
    public Boolean isError(){
        return Objects.equals(this.code, ERROR);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
